part of '../../repository.dart';

const _kGooglePlayPurchasedSubscriptionUserCancellationTimeKey = 'time';
const _kGooglePlayPurchasedSubscriptionUserCancellationSurveyResultKey = 'survey_result';

class _GooglePlayPurchasedSubscriptionUserCancellationInfoDto extends Equatable
    implements _GooglePlayPurchasedSubscriptionCancellationInfoDto {
  const _GooglePlayPurchasedSubscriptionUserCancellationInfoDto._internal({
    required this.timeDto,
    required this.surveyResultDto,
  });

  final ApiTimeDto timeDto;
  final _GooglePlayPurchasedSubscriptionCancellationSurveyResultDto surveyResultDto;

  @override
  String get type => _kGooglePlayPurchasedSubscriptionUserCancellationInfoTypeValue;

  @override
  List<Object?> get props {
    return [
      timeDto,
      surveyResultDto,
    ];
  }

  factory _GooglePlayPurchasedSubscriptionUserCancellationInfoDto.fromJson(
      Map<String, dynamic> json) {
    final timeString = json[_kGooglePlayPurchasedSubscriptionUserCancellationTimeKey] as String;
    final timeDto = ApiTimeDto.fromString(timeString);

    final surveyResultJson = json[_kGooglePlayPurchasedSubscriptionUserCancellationSurveyResultKey]
        as Map<String, dynamic>;
    final surveyResultDto =
        _GooglePlayPurchasedSubscriptionCancellationSurveyResultDto.fromJson(surveyResultJson);

    return _GooglePlayPurchasedSubscriptionUserCancellationInfoDto._internal(
      timeDto: timeDto,
      surveyResultDto: surveyResultDto,
    );
  }

  @override
  GooglePlayPurchasedSubscriptionUserCancellationInfo toEntity() {
    return GooglePlayPurchasedSubscriptionUserCancellationInfo(
      time: timeDto.toEntity(),
      surveyResult: surveyResultDto.toEntity(),
    );
  }
}
